package com.kuzlak.cms.module.sys.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.kuzlak.cms.module.sys.entity.SysMenu;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
* @author hesenjan
* @description 针对表【sys_menu】的数据库操作Mapper
* @createDate 2024-11-30 23:46:05
* @Entity com.kuzlak.cms.module.sys.entity.SysMenu
*/
public interface SysMenuMapper extends BaseMapper<SysMenu> {
    @Select("SELect * FROM  sys_menu as c where  DELETED=0 AND PARENT_ID=#{parentId} and  ID in(SELECT MENU_ID FROM   sys_role_menu as rd where FIND_IN_SET(rd.ROLE_ID,(SELECT ROLE_ID FROM sys_users where ID=#{userId})))   ORDER BY SORT ASC ")
    List<SysMenu> findByDataList(long userId, long parentId);


    @Select("SELect * FROM  sys_menu as c where   DELETED=0 AND  PARENT_ID=#{parentId}  ORDER BY SORT ASC ")
    List<SysMenu> findByDataAdminList(long parentId);

    @Select("SELect * FROM  sys_menu as c where STATUS=1 AND  DELETED=0 AND   TYPE!=3 and PARENT_ID=#{parentId}   ORDER BY SORT ASC ")
    List<SysMenu> findByDataAdminMenuList(long parentId);

    @Select("SELect * FROM  sys_menu as c where  STATUS=1 AND    DELETED=0 AND    TYPE!=3 and PARENT_ID=#{parentId} and  ID in(SELECT MENU_ID FROM   sys_role_menu as rd where FIND_IN_SET(rd.ROLE_ID,(SELECT ROLE_ID FROM sys_users where ID=#{userId})))   ORDER BY SORT ASC ")
    List<SysMenu> findByDataMenuList(Long userId, long parentId);


    @Select("SELect PERMS_KEY FROM  sys_menu as c where   STATUS=1 AND    DELETED=0 AND   TYPE=3 and   ID in(SELECT MENU_ID FROM   sys_role_menu as rd where FIND_IN_SET(rd.ROLE_ID,(SELECT ROLE_ID FROM sys_users where ID=#{userId})))   ORDER BY SORT ASC ")
    List<String> findByDataKeyList(long userId);


    @Select("SELect PERMS_KEY FROM  sys_menu as c where  STATUS=1 AND   DELETED=0 AND   TYPE=3    ORDER BY SORT ASC ")
    List<String> findByDataAdminKeyList();


    @Select("SELect NAME as name, SORT as sort,  PERMS_KEY as permsKey,  PARAMS as params FROM  sys_menu as c where STATUS=1 AND  DELETED=0 AND   TYPE=3 and   ID in(SELECT MENU_ID FROM   sys_role_menu as rd where FIND_IN_SET(rd.ROLE_ID,(SELECT ROLE_ID FROM sys_users where ID=#{userId})))   ORDER BY SORT ASC ")
    List<Map<String, Object>> findByDataKeyDataList(long userId);


    @Select("SELect  NAME as name, SORT as sort,  PERMS_KEY as permsKey,  PARAMS as params FROM  sys_menu as c where  STATUS=1 AND   DELETED=0 AND   TYPE=3    ORDER BY SORT ASC ")
    List<Map<String, Object>> findByDataAdminKeyDataList();

    @MapKey("id")
    List<Map<String, Object>> findByDataMap(@Param(Constants.WRAPPER) QueryWrapper<SysMenu> queryWrapper);

    @Select("SELect PERMS_KEY FROM  sys_menu as c where     DELETED=0 AND   ID in(SELECT MENU_ID FROM sys_role_menu as rd where FIND_IN_SET(rd.ROLE_ID,(SELECT ROLE_ID FROM sys_users where ID=#{userId})))   ORDER BY SORT ASC ")
    List<String> findByDataPerKeyList(Long userId);

    @Select("SELect PERMS_KEY FROM  sys_menu as c where     DELETED=0 ORDER BY SORT ASC ")
    List<String> findByDataPerKeyAdminList();
}




